﻿@{
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@using SRF.UI.Html
@section header
{

    <link href="/Content/style.css" rel="stylesheet" type="text/css" /> 
    <link href="/Scripts/jqTreeTable/css/jquery.treetable.css" rel="stylesheet" type="text/css" /> 
    <link href="/Scripts/jqTreeTable/css/jquery.treetable.theme.my.css" rel="stylesheet" type="text/css" />  
    <script src="/Scripts/jqTreeTable/js/jquery.treetable.js" type="text/javascript"></script> 
    <script type="text/javascript">
        function search() {
            $(".searchbar").search();
        }
        function resetSearch() {
            //TODO:重设搜索条件
            search();
        }
        function openEditor(action, id) {
            var url, title;
            switch (action) {
                case "add":
                    {
                        url = "edit";
                        title = "新增部门";
                    }
                    break;
                case "update":
                    {
                        url = "edit/" + id;
                        title = "修改部门";
                    }
                    break;
                case "delete":
                    {
                        $.confirm("您确定要删除该部门吗？", "确认删除", function (returnValue) {
                            if (returnValue == "ok") {
                                url = "delete";
                                $.get(url, { id: id }, function (data) { 
                                    if (data) {  //发生异常
                                        alert(data);
                                    }
                                    else {
                                        location.reload();
                                    }
                                });
                            };
                        });
                        return;
                    }
                    break;
                case "view":
                    {
                        url = "view/" + id;
                        title = "查看部门";
                        $.dialog({
                            url: url,
                            title: title,
                            height: 400,
                            width: 640,
                            buttons: {
                                "关闭": {
                                    "class": "btn btn-primary",
                                    "data-dismiss": 'modal'
                                }
                            },
                            loading: function () {
                                $(this).iframeLoading();
                            }
                        });
                        return;
                    }
                    break;
            }
            //新增\修改
            $.dialog({
                url: url,
                title: title,
                height: 400,
                width: 640,
                callback: function (returnValue) {
                    location.reload();
                },
                loading: function () {
                    $(this).iframeLoading();
                }
            });
        }
        function onDialogClosed(id, returnValue) {
            if (returnValue == true)
                location.reload();
        }

        $(function () {
            $(".table").treetable({ expandable: true, initialState: "expanded" }); 
        })
    </script>
}
@section toolbar
{ 
    <input type="button" value="新增" class="btn btn-primary" style="float: right" onclick="return openEditor('add');" />
}
@section searchbar{ 
}
@section list{
    <table class="grid table table-striped table-bordered bootstrap-datatable datatable">
        <thead>
            <tr> 
                <th>名称</th>
                <th>上级部门</th>
                <th>排序</th>
                <th>备注</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (System.Data.DataRow row in Model.Rows)
            {  
                <tr data-tt-id="@row["Id"]" data-tt-parent-id="@row["ParentId"]"> 
                    <td>@row["Name"]</td>  
                    <td>@row["ParentDepartment"]</td> 
                    <td style="width:60px">@row["Rank"]</td>
                    <td>@row["Remark"]</td> 
                    <td class="action" style="width: 80px">
                        <a class="icon-edit" href="javascript:openEditor('update','@row["Id"]');" title="修改"></a>
                        <a class="icon-book" href="javascript:openEditor('view','@row["Id"]');" title="查看"></a>
                        <a class="icon-remove" href="javascript:openEditor('delete','@row["Id"]');" title="删除"></a>
                    </td>
                </tr>
            }</tbody>
    </table>
}
